package cn.itcast.bos.service.base.imp;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.itcast.bos.dao.base.AreaDao;
import cn.itcast.bos.domain.base.Area;
import cn.itcast.bos.service.base.AreaService;

@Service
@Transactional
public class AreaServiceImp implements AreaService {

	@Autowired
	private AreaDao areaDao;

	@Override
	@CacheEvict(value="area",allEntries=true)
	public void save(List<Area> areas) {
		areaDao.save(areas);
	}

	@Override
	@Cacheable("area")
	public Page<Area> findAll(Specification<Area> spec, Pageable pageable) {
		return areaDao.findAll(spec, pageable);
	}

	@Override
	@CacheEvict(value="area",allEntries=true)
	public void saveArea(Area model) {
		areaDao.save(model);

	}

	@Override
	@CacheEvict(value="area",allEntries=true)
	public void delBacth(String[] id) {

		for (String string : id) {
			areaDao.delete(string);
		}
	}

}
